package cn.jack1996.yiyi.auth;

import java.util.Collection;

import cn.jack1996.yiyi.bean.SysUser;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 适配用户类，这里需要实现security里面的UserDetails接口
 *
 * @author Jack魏
 * @since 2023-02-08
 */
@Data
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class CustomUserDetails extends SysUser implements UserDetails {
    /**
     * 构造用户信息
     *
     * @param user 用户信息
     */
    public CustomUserDetails(SysUser user) {
        super(user.getId(), user.getAccount(), user.getPassword(), user.getUserName(), user.getHeadImage(),
                user.getEmail(), user.getPhone(), user.getSex(), user.getStatus(), user.getUpdateTime(),
                user.getCreateTime());
    }
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @Override
    public String getUsername() {
        return super.getAccount();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
